<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="sys" tagdir="/WEB-INF/tags/sys"%>
<%@taglib uri="/WEB-INF/tlds/webui.tld" prefix="webui"%>

<webui:enum var="mergerNumEnum" code="mergerNum"/>
<webui:enum var="orgEnum" code="OrgEnum" appendJs="true"/>
<webui:enum var="isAdoptedTypeEnum" code="isAdoptedType"/>
<script>
//组织名称
function tableOrgEnum(table,data){
	var logs = data.data.content;
	$(logs).each(function(index,element){
		var _self = this;
		var orgName = orgEnum[element.cpContent.orgId];
		var adoptOrgName = orgEnum[element.unitContent.adoptOrgId];
		Vue.set(_self,"adoptOrgName",adoptOrgName);
		Vue.set(_self,"orgName",orgName);
	});
	var contentCount = data.page.totalElements;
	if(!document.getElementById("table_length")){
		$("#grid_adopt_paginate").parent().prev().append("<div id='table_length' style='float:left'></div>");
	}
	if (contentCount > 0) {
		$("#table_length").html("共"+contentCount+"条数据");
	} else {
		$("#table_length").html("");
	}
}
</script>
<webui:panel id="channelsSearch">
	<%-- ------------筛选条件 start---------- --%>
	<webui:form method="get" styleClass="form-horizontal" 
		name="declareSearchForm" id="declareSearchForm"
		action="${contextPath}/adoptDeclareSearch.action">
		<input type="hidden" name="orderBy" id="orderBy"/>
		<input type="hidden" name="field" id="field"/>
		<webui:input label="归并名称" styleClass="col-sm-4" labelClass="col-sm-4"
			inputClass="col-sm-8" type="text" name="name">
		</webui:input>
		<webui:select label="CP名称" styleClass="col-sm-4" labelClass="col-sm-4" 
			inputClass="col-sm-8" name="orgId" id="mergerType" lookup="${orgEnum}" 
			multiple="false">
		</webui:select>
		<webui:select label="申报数量" styleClass="col-sm-4" labelClass="col-sm-4" 
			inputClass="col-sm-8" name="mergerNum" id="mergerNum" lookup="${mergerNumEnum}" 
			multiple="false">
		</webui:select>
		<div class="col-sm-12">
			<webui:select label="是否采纳" styleClass="col-sm-4" labelClass="col-sm-4" 
				inputClass="col-sm-8" name="isAdopted" id="isAdoptedType" lookup="${isAdoptedTypeEnum}" 
				multiple="false">
			</webui:select>
			<webui:datepicker label="申报时间"  styleClass="col-sm-4" name="startTime" labelClass="col-sm-4" 
				inputClass="col-sm-8" beginName="startDeclareTime" beginId="startDeclareTime" 
				endName="endDecalareTime" endId="endDecalareTime" duration="true">
			</webui:datepicker>
			<webui:datepicker label="上线时间"  styleClass="col-sm-4" name="startTime" labelClass="col-sm-4" 
				inputClass="col-sm-8" beginName="startOnLineTime" beginId="startOnLineTime" 
				endName="endOnLineTime" endId="endDecalareTime" duration="true">
			</webui:datepicker>
		</div>
		<div class="col-sm-12">
			<webui:button label="" type="button"  styleClass="col-sm-2 pull-right" onclick="grid_adopt.filter()"
				labelClass="col-sm-1" inputClass="col-sm-3" buttonClass="btn-primary">
				查询
			</webui:button>
		</div>
	</webui:form>
	<%-- ------------筛选条件 end---------- --%>
	
	<%-- ------------------内容显示 start-------------------- --%>
	<webui:table id="grid_adopt" dataUrl="${contextPath}/adoptDeclareSearch.action?sort=id,desc"
	datas="data.content" editorForm="#declareEditor" searchForm="#declareSearch" dataload="tableOrgEnum">
		<webui:column field="code" title="归并名称">{{row.unitContent.name}}</webui:column>
		<webui:column field="name" title="归并数量">{{row.unitContent.contentNum }}</webui:column>
		<webui:column field="adoptOrgName" title="采纳CP名称">{{row.adoptOrgName }}</webui:column>
		<webui:column field="orgName" title="CP名称" >{{row.orgName}}</webui:column>
		<webui:column field="name" title="片名">{{row.cpContent.name }}</webui:column>
		<webui:column field="" title="是否独家">{{row.cpContent.exclusive == 1 ? '独家':'非独家' }}</webui:column>
		<webui:column field="declareTime" title="申报时间">{{row.cpContent.declareTime | moment("YYYY-MM-DD HH:mm:ss")}}</webui:column>
		<webui:column field="planOnlineTime" title="上线时间">{{row.cpContent.planOnlineTime | moment("YYYY-MM-DD HH:mm:ss")}}</webui:column>
		<webui:column field="lastUpdateTime" title="修改时间">{{row.cpContent.lastUpdateTime | moment("YYYY-MM-DD HH:mm:ss")}}</webui:column>
		<webui:column field="ztePlayUrl" title="采纳状态">
			<div v-if="row.cpContent.isAdopted == 0" class="text-center">未采纳</div>
			<div v-if="row.cpContent.isAdopted == 1" class="text-center">已采纳</div>
			<div v-if="row.cpContent.isAdopted == 2" class="text-center">待采纳</div>
		</webui:column>
		<webui:column style="text-align:center" title="操作"> 
			<a v-if="row.cpContent.isAdopted!=1" class="btn btn-xs btn-warning" v-bind:href="'javascript:onAdoptDeclare('+row.id+',\''+row.cpContent.name+'\')'">采纳</a>
			<a v-if="( row.cpContent.isAdopted==1 || row.cpContent.exclusive == 1 ) && row.cpContent.exclusive != 1" class="btn btn-xs btn-primary" v-bind:href="'javascript:onCutAdoptDeclare('+row.id+',\''+row.cpContent.name+'\')'">取消采纳</a>
			<a v-if="( row.cpContent.isAdopted==1 || row.cpContent.exclusive == 1 ) && row.cpContent.exclusive == 1" class="btn btn-xs btn-primary" 
			v-bind:href="'javascript:cancelExclusive('+row.cpContent.id+',\''+row.cpContent.name+'\',\''+row.cpContent.orgId+'\')'">取消独家</a>
		</webui:column>
	</webui:table>
	<%-- ------------------内容显示 start-------------------- --%>
	
</webui:panel>

<script>

$(function(){
	/******************************按照录入时间排序*************************************/
	var createOrderBy = "desc";
	$("#planOnlineTime_title").click(function(){
		$("#field").val("planOnlineTime");
		if(createOrderBy == "desc"){
			createOrderBy = "asc";
			$("#orderBy").val("asc");
		}else if(createOrderBy == "asc"){
			createOrderBy = "desc";
			$("#orderBy").val("desc");
		}
		if(!document.getElementById("onlineTimeOrderIcon")){
			$(this).append("<span id='onlineTimeOrderIcon' class='glyphicon'></span>");
		}
		if(document.getElementById("declareTimeOrderIcon")){
			$("#declareTimeOrderIcon").remove();
		}
		tableSort(createOrderBy,"onlineTime");
	});
	/******************************按照申报时间排序*************************************/
	var declareOrderBy = "desc";
	$("#declareTime_title").click(function(){
		$("#field").val("declareTime");
		if(declareOrderBy == "desc"){
			declareOrderBy = "asc";
			$("#orderBy").val("asc");
		}else if(declareOrderBy == "asc"){
			declareOrderBy = "desc";
			$("#orderBy").val("desc");
		}
		if(!document.getElementById("declareTimeOrderIcon")){
			$(this).append("<span id='declareTimeOrderIcon' class='glyphicon'></span>");
		}
		if(document.getElementById("onlineTimeOrderIcon")){
			$("#onlineTimeOrderIcon").remove();
		}
		tableSort(declareOrderBy,"declareTime");
	});
});

function tableSort(order,field){
	grid_adopt.filter();
	if(order == "desc"){
		$("#"+field+"OrderIcon").removeClass("glyphicon-chevron-up");
		$("#"+field+"OrderIcon").addClass("glyphicon-chevron-down");
	}else if(order == "asc"){
		$("#"+field+"OrderIcon").removeClass("glyphicon-chevron-down");
		$("#"+field+"OrderIcon").addClass("glyphicon-chevron-up");
	}
	
}

//取消采纳 
function onCutAdoptDeclare(id,name){
	confirm(name+'将会被取消采纳，是否继续进行?', function(result){
		$.ajax({
			method:'get',
			url:'${contextPath}/cancelAdopt.action?id='+id,
			success:function(){
				grid_adopt.reload();
				showMessage('提示', name+',采纳已取消！');
			}	
		}); 
	});
}
//采纳
function onAdoptDeclare(id,name){
	confirm('将会采纳'+name+'CP，是否继续进行?', function(result){
		$.ajax({
			method:'get',
			url:'${contextPath}/adoptCp.action?id='+id+'&rowId='+id,
			success:function(){
				grid_adopt.reload();
				showMessage('提示', name+',采纳成功！');
			}	
		}); 
		
	});
}

//取消独家按钮
function cancelExclusive(id,name,orgid){
	confirm('是否取消\"'+name+'\"为独家数据？取消以后将会变成非独家数据',function(result){
		$.ajax({
			method:"get",
			url:'${contextPath}/cancelExclusive.action?id='+id,
			success:function(){
				grid_adopt.reload();
				showMessage('提示', name+'独家，取消成功！'); 
			}
		});
	});
}


</script>

